package com.gugee.tiktok.web.repository;

import com.gugee.tiktok.web.dto.BloggerRecordResponse;
import com.gugee.tiktok.web.dto.BloggerResponse;
import com.gugee.tiktok.web.model.mysql.TBlogger;
import org.springframework.data.jdbc.repository.query.Modifying;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface TBloggerRepository extends CrudRepository<TBlogger,Long> {

    @Query("SELECT * FROM t_blogger WHERE user_id = :userId ORDER BY blogger_sort DESC")
    List<BloggerResponse> findByUserIdOrderByBloggerSortDesc(long userId);

    TBlogger findByUserIdAndUidOrderByBloggerSort(long userId,long uid);

    List<TBlogger> findByUserId(long userId);

    @Modifying
    @Query("DELETE FROM t_blogger WHERE user_id = :userId AND uid = :uid")
    void deleteByUserIdAndUid(long userId,long uid);

    /**
     * 获取my tiktioker播主列表信息(总数据)
     * @param userId
     * @param limitCount
     * @return
     */
    @Query("SELECT t2.*, t3.score, t3.o_follower_count follower_count, t3.o_aweme_count posts_count, t3.o_total_favorited like_count " +
            "FROM (SELECT t1.* FROM t_blogger t1 WHERE user_id = :userId ) t2 " +
            "LEFT JOIN blogger_main t3 ON t2.uid = t3.o_uid " +
            "ORDER BY blogger_sort DESC limit :limitCount")
    List<BloggerRecordResponse> findBloggersByUserIdOrderByBloggerSortDesc(long userId, int limitCount);
}
